import React, { useState } from 'react';
import { getTest2 } from '../../api/promsie';
import { reduceRequest } from '../../utils/reduceRequest';

export default function ReduceComponent(): JSX.Element {
  const [result, setResult] = useState<string>('失败');
  function requestInit(): void {
    // getTest2(1).then((res) => {
    //   console.log(res);
    //   setResult(JSON.stringify(res));
    // });
    reduceRequest(getTest2)(1, { retryCount: 40, retryInterval: 1000 }).then(
      (res) => {
        setResult(JSON.stringify(res));
      }
    );
  }
  return (
    <>
      <h1>失败重连</h1>
      <h2>{result}</h2>
      <button onClick={() => requestInit()}>失败会重连嘛</button>
    </>
  );
}
